import java.util.Observable;

/*
 * Die Klasse <code>Time</code> ist das Concrete Subject des hier implementierten Observers
 * 
 * @author paraa
 * @version 12.12.09
 * 
 */


public class Time extends Observable{
	private int currentTime;
	private int endOfTime;
	private static Time theTime;
	
	public Time() {
		currentTime = 0;
	}
	
	/*
	 * Singleton Entwurfsmuster!
	 */
	
	public static Time getInstance() {
		if (theTime == null)
			theTime = new Time();
		return theTime;
	}
	
	public void initEndOfTime(int numberOfSeconds) {
		endOfTime = numberOfSeconds;
	}
	
	public int getCurrentTime() {
		return currentTime;
	}
	
	public void run() {
		while (currentTime < endOfTime) {
			currentTime++;
			setChanged();			// Marks this Observable object as having been changed; the hasChanged method will now return true.
			notifyObservers();		// beim Aufruf von notifyObservers() wird in jedem Observer die update() Methode aufgerufen
		}
	}
}
